﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace gisgeb.plugins.newsolution
{
    public partial class ComponentenNameDialog : Form
    {
        public ComponentenNameDialog()
        {
            InitializeComponent();
        }

        private void ComponentenName_Load(object sender, EventArgs e)
        {
            this.btnOk.Enabled = false;            
        }

        private void txtComponentName_TextChanged(object sender, EventArgs e)
        {
            this.btnOk.Enabled = this.IsValidFolderName(this.txtComponentName.Text);
        }

        private bool IsValidFolderName(string text)
        {
            //TODO: Is there a regex defining a valid folder-name?
            if (string.IsNullOrEmpty(text))
            {
                return false;
            }

            if (text.Contains(" "))
            {
                return false;
            }

            return true;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            string text = this.txtComponentName.Text;
            if(!this.IsValidFolderName(text))
            {
                return;
            }

            this.ComponentName = text;
            this.Close();
        }

        public string ComponentName { get; set; }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.ComponentName = null;
            this.Close();
        }
    }
}
